<?php

Raise::load('core.Url');

/**
 * Testing Unit of 'phpraise/core/Url.php'
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.UnitTest.Test
 */
class TestCoreUrl extends RaiseTest {

    public static function testType(){
        self::assertClassExists('Url');
        self::assertClassExtends('Url', 'RaiseDataType');
        self::assertObjectClass(new Url(), 'Url');
    }

    public static function testParsing(){
        $strUrl = 'http://example.com/';
        $url = new Url($strUrl);
        self::assertEqual($url, $strUrl);
        self::assertStrictEqual($url->host(), 'example.com');
        self::assertStrictEqual($url->scheme(), 'http');
    }

    public static function testParsing2(){
        $strUrl = 'https://en.wikipedia.org/';
        $url = new Url($strUrl);
        self::assertEqual($url, $strUrl);
        self::assertStrictEqual($url->host(), 'en.wikipedia.org');
        self::assertStrictEqual($url->scheme(),'https');
    }

    public static function testParsing3(){
        $strUrl = 'ftp://user1:test@ftp.example.com/';
        $url = new Url($strUrl);
        self::assertEqual($url, $strUrl);
        self::assertStrictEqual($url->host(), 'ftp.example.com');
        self::assertStrictEqual($url->scheme(),'ftp');
        self::assertStrictEqual($url->user(), 'user1');
        self::assertStrictEqual($url->pass(), 'test');
    }

    public static function testEncodeDecode(){
        self::assertStrictEqual(Url::encode('test@live.com'), 'test%40live.com');
        self::assertStrictEqual(Url::decode('test%40live.com'), 'test@live.com');
    }

    public static function testCombine(){
        self::assertStrictEqual(Url::combine('http://localhost/example/root', '..')->__toString(), 'http://localhost/example');
        self::assertStrictEqual(Url::combine(new Url('http://localhost/example/root'), '..\..')->__toString(), 'http://localhost/');
        self::assertObjectClass(Url::combine('http://localhost/example/root', '..\..'), 'Url');
        self::assertObjectClass(Url::combine(new Url('http://localhost/example/root'), '..\..'), 'Url');
        self::assertStrictEqual(Url::combine('script', 'lib/jquery.js'), 'script/lib/jquery.js');
        self::assertType(Url::combine('script', 'lib/jquery.js'), 'string');
    }

}
